<?php 
header("Content-Type: text/html; charset=UTF-8");
$y = date('m',time());
$r = date('d',time());

$url = "http://api.juheapi.com/japi/toh";
$appkey="81ca65e7dad4f8839f50b9b3408a86be";
$params = array(
      "key" => $appkey,//应用APPKEY(应用详细页查询)
      "v" => "1.0",//版本，当前：1.0
      "month" => $y,//月份，如：10
      "day" => $r,//日，如：1
);
$paramstring = http_build_query($params);
$content = juhecurl($url,$paramstring);
$result = json_decode($content,true);
if($result){
    if($result['error_code']=='0'){
        // print_r($result['result']);
        $temp = array_rand($result['result'],1);
        $jieguo= $result['result'][$temp]['des'];

    }else{
        $jieguo= $result['error_code'].":".$result['reason'];
    }
}else{
    $jieguo= "请求失败";
}
function juhecurl($url,$params=false,$ispost=0){
    $httpInfo = array();
    $ch = curl_init();
 
    curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
    curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );
    curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
    curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    if( $ispost )
    {
        curl_setopt( $ch , CURLOPT_POST , true );
        curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
        curl_setopt( $ch , CURLOPT_URL , $url );
    }
    else
    {
        if($params){
            curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
        }else{
            curl_setopt( $ch , CURLOPT_URL , $url);
        }
    }
    $response = curl_exec( $ch );
    if ($response === FALSE) {
        //echo "cURL Error: " . curl_error($ch);
        return false;
    }
    $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
    $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
    curl_close( $ch );
    return $response;
}
 ?>